CFLAGS = -g -O2 -Wall 
LDFLAGS = 
LIBS = 

ERLANG_CFLAGS = -I/usr/local/lib/erlang/lib/erl_interface-3.6.4/include -I/usr/local/lib/erlang/usr/include
ERLANG_LIBS = -L/usr/local/lib/erlang/lib/erl_interface-3.6.4/lib -lerl_interface -lei

DYNAMIC_LIB_CFLAGS = -fpic -shared


ERLSHLIBS = iconv_erl.so


all:  $(ERLSHLIBS) iconv.beam test.beam iconv_test


$(ERLSHLIBS):	%.so:	%.c 
	gcc $(CFLAGS) $(LDFLAGS) $(INCLUDES) \
		$(subst ../,,$(subst .so,.c,$@)) $(LIBS) \
		$(ERLANG_LIBS) \
		$(ERLANG_CFLAGS) \
		-o $@ \
		$(DYNAMIC_LIB_CFLAGS)

iconv.beam: iconv.erl
	erlc -o $@ $<

test.beam: test.erl
	erlc -o $@ $<

iconv_test: iconv_test.c
	gcc -o $@ $<

clean:
	rm -rfv iconv_test
	rm -rfv *.beam
	rm -rfv *.so
	rm -rfv *~

